package org.mozhu.zufang.system.auth.service;

import com.google.common.collect.Sets;
import org.mozhu.zufang.system.auth.entity.GroupAuth;
import org.mozhu.zufang.system.group.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Set;

public abstract class AbstractGroupAuthorityService extends AbstractAuthorityService implements AuthorityService {

    @Autowired
    GroupService groupService;

    @Autowired
    GroupAuthService groupAuthService;

    protected Set<Long> groupAuthsToRoleIds(List<GroupAuth> groupAuths) {
        Set<Long> roleIds = Sets.newHashSet();
        for (GroupAuth groupAuth : groupAuths) {
            roleIds.addAll(groupAuth.getRoleIds());
        }
        return roleIds;
    }

    protected Set<Long> groupAuthsToPermissionIds(List<GroupAuth> groupAuths) {
        Set<Long> permissionIds = Sets.newHashSet();
        for (GroupAuth groupAuth : groupAuths) {
            permissionIds.addAll(groupAuth.getPermissionIds());
        }
        return permissionIds;
    }
}
